/*
 * XPath.java
 *
 * Created on April 15, 2005, 3:00 PM
 */

package com.smallx.xpath;

import org.infoset.xml.XMLException;

/**
 *
 * @author R. Alexander Milowski
 */
public class XPath
{
   static Class xpathFactoryClass;
   static XPathFactory defaultXPathFactory;
   static {
      try {
         String className = System.getProperty("com.smallx.xml.xpath.Implementation","com.smallx.xml.xslt.xt.XTXPathFactory");
         xpathFactoryClass = Class.forName(className);
      } catch (Exception ex) {
         System.err.println("Cannot load xpath implementation!!!");
         ex.printStackTrace();
      }
      try {
         defaultXPathFactory = newXPathFactory();
      } catch (XMLException ex) {
         ex.printStackTrace();
      }
   }
   
   /** Creates a new instance of XPath */
   protected XPath()
   {
   }
   
   public static XPathFactory newXPathFactory() 
      throws XMLException
   {
      try {
         return (XPathFactory)xpathFactoryClass.newInstance();
      } catch (Exception ex) {
         throw new XMLException("Cannot create instance due to class error.",ex);
      }
   }
   
   public static XPathFactory getDefaultFactory() {
      return defaultXPathFactory;
   }
      
}
